﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Workflow.Task;
using Jzy.Workflow.Form;
using Frame.Lib.Core.Attach;


namespace Jzy.Web.WorkFlow.Fore.Controls
{
    public partial class Attachs : System.Web.UI.UserControl
    {
        private FlowTaskBO _task;
        private FlowTaskBO Task
        {
            get
            {
                if (_task == null)
                {
                    _task = new FlowTaskBO();
                }
                return _task;
            }
        }
        private FlowTaskInfo _taskInfo;
        private FlowTaskInfo TaskInfo
        {
            get
            {
                if (_taskInfo == null)
                {
                    if (!string.IsNullOrEmpty(TaskID))
                    {
                        _taskInfo = Task.GetInfo(TaskID);
                    }
                }
                return _taskInfo;
            }
            set
            {
                _taskInfo = value;
            }
        }

        /// <summary>
        /// 这个任务是怎么过来的
        /// </summary>
        protected FromType TaskFromType
        {
            get
            {
                if (TaskInfo == null)
                {
                    return FromType.新建;
                }
                else
                {
                    return (FromType)TaskInfo.FromType;
                }
            }
        }

        /// <summary>
        /// 不为空即为审批，为空就是新增
        /// </summary>
        private string TaskID//有可能要加密
        {
            get
            {
                return Request["TaskID"];
            }
        }

        public int AttachCount
        {
            get;
            set;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               // InitData();
            }
        }
        

        public void InitData()
        {
            if (TaskFromType == FromType.新建)
            {
                pnlAddFile.Visible = true;
                pnlDispFile.Visible = false;
            }
            else
            {               

                pnlAddFile.Visible = false;
                pnlDispFile.Visible = true;

                //显示附件列表
                AttachBO attach = new AttachBO("FlowFormAttach");
                IEnumerable<AttachInfo> dt = attach.GetList(this.TaskInfo.FormInfo.ID);
                this.lvAttach.DataSource = dt;
                lvAttach.DataBind();

                this.AttachCount = dt.Count();
            }
        }
    }
}